package com.fuluwa.depart.pc.interfaces.web;

import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * LoginController负责打开登录页面(GET请求)和登录出错页面(POST请求)，真正登录的POST请求由Filter完成
 * 
 * <pre>
 * 	Shiro校验用户是否登录 TODO
 * </pre>
 * 
 * @author leasenli
 * 
 */
@Controller
public class LoginController extends BaseController {

	/**
	 * 进入到login页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login() {
		return "login";
	}
	
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName, Model model) {
		model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, userName);
		return "login";
	}
	
	@RequestMapping(value = "/loginSucc", method = RequestMethod.GET)
	@ResponseBody
	public Result succ() {
		result = createSuccResult();
		return result;
	}

	@RequestMapping(value = "/loginFail", method = RequestMethod.GET)
	@ResponseBody
	public Result fail() {
		result = createFailResult(-1, "Check UserInfo Fail!");
		return result;
	}

}
